/**
 * 
 */
package com.swim.sys.web;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.collections.CollectionUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.swim.sys.entity.SysSet;
import com.swim.sys.service.SysSetService;

/**
 * 系统配置表Controller
 * @author ljw
 * @version 2023-06-19
 */
@Controller
@RequestMapping(value = "${adminPath}/sys/sysSet")
public class SysSetController extends BaseController {

	@Autowired
	private SysSetService sysSetService;
	
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public SysSet get(String id, boolean isNewRecord) {
		return sysSetService.get(id, isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
	@RequiresPermissions("sys:sysSet:view")
	@RequestMapping(value = {"list", ""})
	public String list(SysSet sysSet, Model model) {
		model.addAttribute("sysSet", sysSet);
		return "swim/sys/sysSetList";
	}
	
	/**
	 * 查询列表数据
	 */
	@RequiresPermissions("sys:sysSet:view")
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<SysSet> listData(SysSet sysSet, HttpServletRequest request, HttpServletResponse response) {
		Page<SysSet> page = sysSetService.findPage(new Page<SysSet>(request, response), sysSet); 
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("sys:sysSet:view")
	@RequestMapping(value = "form")
	public String form(SysSet sysSet, Model model) {
		//查询表中的第一条数据
		List<SysSet> sysSetList = sysSetService.findList(new SysSet());
		if (CollectionUtils.isNotEmpty(sysSetList)) {
			sysSet = sysSetList.get(0);
		}
		model.addAttribute("sysSet", sysSet);
		return "swim/sys/sysSetForm";
	}

	/**
	 * 保存系统配置表
	 */
	@RequiresPermissions("sys:sysSet:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated SysSet sysSet) {
		sysSetService.save(sysSet);
		return renderResult(Global.TRUE, text("保存系统配置表成功！"));
	}
	
	/**
	 * 获取详情数据
	 */
	@RequestMapping(value = "detailsData")
	@ResponseBody
	public String detailsData() {
        List<SysSet> sysSetList = sysSetService.findList(new SysSet());
		return renderResult(Global.TRUE, text("获取详情数据成功！"), sysSetList.get(0));
	}
	
}